<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/css/layui.css"  tppabs="http://res.layui.com/layui/dist/css/layui.css" media="all"></head>
    <script src="/layui/layui.js"></script>
<body>
<h1 style="text-align: center">书库管理系统</h1><form action="#" class="layui-form">
    <div style="text-align: center">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label>图书名称:</label>
            <div class="layui-inline">
                <input type="text" name="bookname" autocomplete="off" placeholder="请输入图书名称"
                       class="layui-input">
            </div>
            价格区间<input type="text" name="a" placeholder="请输入价位" >
            -
            <input type="text" name="b" placeholder="请输入价位" >

            <button class="layui-btn" lay-submit lay-filter="tdemo">搜索</button>
        </div>
    </div>
    </div>
</form>

<script type="text/html" id="token-bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit-token">编辑</a>
    <button class="layui-btn layui-btn-sm layui-btn-danger" id="aa" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</button>
</script>
<div style="text-align: center">
    <div class="layui-inline">
        <table id="tdemo" lay-filter="tdemo"></table>
    </div>
</div>
<script>
    layui.use(['table', 'layer', 'form'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        form.render();
        table.render({
            id: "tdemo",
            elem: '#tdemo'
            , cellMinWidth: 80
            , url: '/book/page' //数据接口
            , page: true //开启分页
            , cols: [[
                {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
                ,{field: 'bookname', title: '图书名', width:150}
                ,{field: 'bookprice', title: '图书价格', width:150, sort: true}
                ,{field: 'bookpress', title: '出版社', width:150}
                , {fixed: 'right', title: '操作', toolbar: '#token-bar', width: 180}
            ]]
        });
        table.on('toolbar(tdmo)', function (obj) {
            switch (obj.event) {
                case 'goEdit':
                    openEditWindow(null);
                    break;
                case 'delete':
                    var data = table.checkStatus('tdmo').data;
                    if (data.length > 0) {
                        layer.confirm('真的删除行么', function (index) {
                            var param = ""
                            $.each(data, function (i, obj) {
                                param += "&id=" + obj.id
                            })
                            $.ajax({
                                url: '/recharge/del',
                                data: param,
                                method: 'post',
                                success: function (result) {
                                    if (result.status) {
                                        table.reload('tdmo', {});
                                    } else {
                                        alert(result.msg)
                                    }
                                    layer.close(index);
                                }
                            })
                        });
                    }
                    break;
            }
            ;
            ;

        //给搜索框赋值,使点击搜索令分页添加参数
        form.on('submit(tdemo)', function (data) {
            table.reload('tdemo', {
                where: data.field
            });
            return false; //阻止表单跳转
        });


    });
</script>
</body>
</html>